<?php
/**
 * 
 * @author bqd
 *
 */

class ExtendedTranslateBehavior extends ModelBehavior {
	var $options = array();
    function setup(&$model, $settings = array()) {
		if (isset($model->overrideTranslation) && isset($model->overrideTranslation['fields']) && !empty($model->overrideTranslation['fields'])) {
			$model->unbindTranslation();
			$model->bindTranslation($model->overrideTranslation['fields'], false);
		}
    }
    
    function afterSave(&$model, $created) {
    	if ($created) {
    		$languages = Configure::read('Config.languages');
    		
    		$saved_locale = $model->locale;
    		$data = $model->data;
    		foreach ($languages as $langCode => $language) {
    			if ($language != $saved_locale) {
    				$model->locale = $language;
    				$model->save($data);
    			}
    		}
    	}
    }
}
?>